//
//  BRCopuonCVCell.m
//  Chargebull
//
//  Created by 甘卫国 on 2024/1/9.
//

#import "BRCopuonCVCell.h"

@implementation BRCopuonCVCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (void)setDto:(BRCouponModel *)dto {
    _dto = dto;
    
    // 抵扣类型：1-金额 2-时间 3-折扣
    NSInteger couponType = dto.deductionType;
    NSString *title1 = [BRStringTools br_couponsTypeStr:couponType];
    NSString *text1 = [BRStringTools br_couponsTypeContentV2:dto.deduction];
    self.titleL.text = [NSString stringWithFormat:@"%@ %@",title1,text1];
    self.textL.text = [NSString stringWithFormat:@"%@: %@",Localized(@"wallet_expiryDate"),[BRTools getTimeFromTimestamp:dto.endTime.integerValue formatter:@"dd MMM, yyyy"]];
//    self.titleL.text = dto.title;
//    NSString *title = dto.title;
//    NSString *l1 = Localized(@"Rewards_allLocation");
//    if (dto.merchantNameList.length != 0) {
//        //
//        l1 = dto.merchantNameList;
//    }
//    NSString *time = [BRTools br_timeForMatterDay:[dto.endTime integerValue]];
//    NSString *l2 = [NSString stringWithFormat:@"%@: %@",Localized(@"Rewards_avaiableUntil"),time];
//    NSString *r1 = [self myCouponStatus:dto.state];
//    if (dto.state == 3) {
//        // 已过期样式
//        self.payTypeImg.image = [UIImage qd_rewardLocationImg2];
//        self.leftImg2.image = [UIImage qd_rewardCalenderImg2];
//        UIColor *exColor = [BRThemeManage br_05AlphaColor];
//        self.titleLB.textColor = exColor;
//        self.priceLB.textColor = exColor;
//        self.describeLB.textColor = exColor;
//        self.doStausLb.textColor = exColor;
//    }
//    self.titleLB.text = title;
//    self.priceLB.text = l1;
//    self.describeLB.text = l2;
//    self.doStausLb.text = r1;
    
    self.isSel = dto.isSel;
}

- (void)setIsSel:(BOOL)isSel {
    _isSel = isSel;
    self.selBtn.hidden = !isSel;
    self.useBtn.hidden = isSel;
}

#pragma mark - UI --
- (void)setUI {
    
    self.contentView.backgroundColor = UIColor.clearColor;
    self.backgroundColor = UIColor.clearColor;
    
    UIView *contView = [[UIView alloc] init];
    [self.contentView addSubview:contView];
    [contView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(14);
        make.left.offset(28);
        make.right.offset(-28);
        make.bottom.offset(0);
    }];
    
    contView.backgroundColor = kColorBGF5;
    contView.layer.cornerRadius = 10;
    contView.layer.masksToBounds = YES;
    
    UIStackView *stack = [[UIStackView alloc] init];
    stack.spacing = 14;
    stack.axis = UILayoutConstraintAxisVertical;
    [contView addSubview:stack];
    [stack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(14);
        make.left.offset(14);
        make.bottom.offset(-14);
        make.right.offset(-70);
    }];
    
    self.titleL = [BRToolsView br_label:@"--" textColor:kColorTitle font:[UIFont fontS:17]];
    self.titleL.numberOfLines = 2;
    self.textL = [BRToolsView br_label:@"--" textColor:kColorTitle66B font:[UIFont fontM:13]];
    [stack addArrangedSubview:self.titleL];
    [stack addArrangedSubview:self.textL];
    
    
    self.selBtn = [[QMUIButton alloc] init];
    [self.selBtn setImage:UIImageMake(@"pay_selCoupon") forState:UIControlStateNormal];
    self.selBtn.layer.cornerRadius = 7;
    self.selBtn.layer.masksToBounds = YES;
    self.selBtn.layer.borderWidth = 1;
    self.selBtn.layer.borderColor = kColorMain.CGColor;
    
    [contView addSubview:self.selBtn];
    [self.selBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.width.mas_equalTo(56);
        make.height.mas_equalTo(30);
        make.right.offset(-14);
    }];
    
    self.useBtn = [[QMUIButton alloc] init];
    [self.useBtn setBackgroundColor:kColorMain];
    [self.useBtn setTitle:Localized(@"order_use") forState:UIControlStateNormal];
    [self.useBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    self.useBtn.titleLabel.font = [UIFont fontM:12];
    self.useBtn.layer.cornerRadius = 7;
    self.useBtn.layer.masksToBounds = YES;
    self.useBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 12);
    [contView addSubview:self.useBtn];
    [self.useBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.width.mas_greaterThanOrEqualTo(56);
        make.height.mas_equalTo(30);
        make.right.offset(-14);
    }];
    
    self.selBtn.userInteractionEnabled = NO;
    self.useBtn.userInteractionEnabled = NO;
    
}

@end
